package com.gitee.wsl.func.procedure.sample

import com.gitee.wsl.base.Option
import com.gitee.wsl.base.empty
import com.gitee.wsl.func.procedure.Procedure


abstract class ComparatorProcedure<T> protected constructor(
    protected val comparator: Comparator<in T>
) : Procedure<T> {
    var isVisitedAtLeastOnce: Boolean = false
        protected set
    private var result: T? = null

    fun getResult(): T? {
        if (!this.isVisitedAtLeastOnce) {
            throw NoSuchElementException()
        }
        return this.result
    }

    val resultOptional: Option<T>
        get() {
            if (!this.isVisitedAtLeastOnce) {
                return Option.empty()
            }
            return Option.fromNullable(this.result)
        }

}
